﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Downloads : Acms.AcmsControls.ContentControls.Admin.BaseCustomAdminControl
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        grid.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(grid_NeedDataSource);
        downloadGrid.DataBinding += new EventHandler(downloadGrid_DataBinding);
    }

    void  downloadGrid_DataBinding(object sender, EventArgs e)
    {
        downloadGrid.DataSource = GetData();
    }

    void grid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        grid.DataSource = GetData();
    }

    protected IQueryable GetData()
    {
        ClimateChangeChampionsData.DataContext context = new ClimateChangeChampionsData.DataContext();
        var groups = from item in context.Downloads
                     group item by item.Path into g
                     select new { Path = g.Key, Name = g.First().Name, Count = g.Count() };
        return groups;
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
